// pages/shoutu/shoutu.js
const httpUtils = require('../../utils/httpUtils')
const ui = require('../../utils/ui')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    noticeStr: '',
    shareCode: '',
    jinriShareNum: 0,
    leijiShareNum: 0,
    leijiCoinNum: 0,
    shareRewardDescription: '',
    isLogin: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (wx.getStorageSync('USERDATA')) {
      this.setData({
        isLogin: true,
        shareCode: wx.getStorageSync('USERDATA').shareCode
      })
      this.requestShareInfo();
    } else {
      this.setData({
        isLogin: false
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '快来和我一起赚点零花钱',
      path: '/pages/login/login?shareCode='+wx.getStorageSync('USERDATA').shareCode
    }
  },
  //请求分享信息
requestShareInfo() {
  let obj = {
    method: 'GET',
    url: '/user/' + wx.getStorageSync('USERDATA').platformId + '/share-info'
  }
  httpUtils.request(obj).then(res => {
    this.setData({
      noticeStr: res.data.shareTips,
    shareRewardDescription: res.data.shareRewardDescription,
    jinriShareNum: res.data.shareUserTodayCount,
    leijiShareNum: res.data.shareUserAllCount,
    leijiCoinNum: res.data.shareUserCoinCount,
    })
  }).catch(err => {
    console.log('ERROR')
  });
},
//复制邀请码
actionCopyShareCode() {
  wx.setClipboardData({
    data: wx.getStorageSync('USERDATA').shareCode,
    success: function(res) {
      ui.showToast("复制成功");
    }
  });
},
//查看收益明细
actionShowShouyi() {
wx.navigateTo({
  url: '/pages/shoutu/shouyi',
})
},
//邀请好友
actionShare() {
  console.log('点击分享')
  wx.showShareMenu({
    withShareTicket: true,
    menus: ['shareAppMessage', 'shareTimeline']
  })
},
//登录
actionLogin() {
  wx.navigateTo({
    url: '/pages/login/login',
  })
}
})